#include <vector>
#include <stdio.h>
 std::vector<std::vector<int> > generateMatrix(int n) {
        if(n<=0)
            return ;
        limit = n * n;
        int i = 0;
        int j = 0;
        int c = 1;
        std::vector<std::vector<int>> v;
        for (i = 0; i < n; ++i)
        {
            for (int j = 0; j < n; ++j)
            {
                v[i].push_back(0);
            }
        }
        while(1){
            if(c > limit)
                break;
            while((c <= limit) && (i < (n - 1 - j)))
                v[i++][j] = c++;

            i--;
            while((c <= limit) && (j <= i))
                v[i][j++] = c++; 
            j--;
            while((c <= limit) && (i > (n - 1 - j)))
                v[i--][j] = c++;
            i++;
            while((c <= limit) && (j >= i))
                v[i][j--] = c++; 
            j++;
        }
        return v;
    }

void print_vector(std::vector<std::vector<int>> v;)
{
    int size = v.size()
    for (int i = 0; i < size; ++i)
    {
        for (int j = 0; i < size; ++j) {
            printf("%d ", v[i][j]);
        }
    }
    
}

int main(int argc, char const *argv[])
{
    std::vector<std::vector<int>> v;
    v = generateMatrix(3);
    print_vector(v);
    return 0;
}